﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partial class banners_uc_banners : DAO.ESWebUserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        InitializeUI();
        //if(!Page.IsPostBack)
            LoadData();
    }

    protected override void InitializeUI()
    {
        long langId = DAO.Connection.DEFAULT_LANGUAGE;
        if (Session["language"] != null)
            long.TryParse(Session["language"].ToString(), out langId);

        this.LangId = Convert.ToInt32(langId);
    }

    private void LoadData()
    {
        using (SqlConnection conn = new SqlConnection(DAO.Connection.CONN_STRING1))
        {
            conn.Open();
            using (SqlCommand cmd = new SqlCommand("SELECT * FROM dbo.Fn_GetAllBanners() WHERE isActive='true' and position='true'", conn))
            {
                SqlDataReader dr = null;
                dr = cmd.ExecuteReader();
                if (dr != null)
                {
                    HyperLink h;
                    while (dr.Read())
                    {
                        h = new HyperLink();
                        Image img = new Image();
                        img.ImageUrl = "~/images/banners/" + dr["id"].ToString() + "_" + dr["filename"].ToString();
                        img.Width = Unit.Pixel(195);
                        //img.Height = Unit.Pixel(150);
                        img.Style.Add("margin-bottom", "15px");
                        h.Controls.Add(img);
                        h.NavigateUrl = "HTTP://" + dr["link"].ToString();
                        h.Target = "_blank";
                        phBanners.Controls.Add(h);
                    }
                }
                dr.Close();
            }
        }
    }
}
